<template>
	<view class="container">

		<view class="top-box">
			<image :src="topImage" class="bg"></image>
			<view class="top-content">
				<view class="top-title">
					{{weather.temperature}}℃
					<span style="margin-left: 20px;">{{weather.weather}}</span>
				</view>
				<view class="top-search">
					<view class="top-location">
						<uni-icons type="location-filled" color="#ffffff" size="20"></uni-icons>
						<view style="margin-left: 20upx;color: white;">
							剑阁县
						</view>
					</view>
				</view>
				<view class="top-notice">
					<uni-notice-bar showIcon="true" scrollable="true" :speed="50" single="true" :text="noticeText" color='#6A6F76'>
					</uni-notice-bar>
				</view>
			</view>
		</view>

		<view class="info-box">
			<!-- F1 菜单 开始 -->
			<view class="first-container">
				<view class="item" v-for="(item,index) in fristBoxList" :key="index" @click="goPage(item.path,item.checked)">
					<image :src="item.icon" mode=""></image>
					<view class="">{{item.title}}</view>
				</view>
			</view>
			<!-- F1 菜单 结束 -->

			<!-- F2 在线办事 |办事指南 开始 -->
			<view class="problem-box">
				<image src="@/static/image/index/online-service.png" mode="widthFix" @click="goPage('/pages/declare/declareIndex','LOGIN')" />
				<image src="@/static/image/index/issue-guide.png" mode="widthFix" @click="goPage('/pages/smartaffairs/affairlist','LOGIN')" />
				<!-- <view class="title-box">
					<image src="https://cdjjyl.com.cn/imageCollection/jiange/indexImage/bmfw.png"
						style="width:260upx;height: 50upx;"></image>
				</view>
				<view class="second-box">
					<view class="item-box" v-for="(item,index) in secondBoxList" :key="index"
						@click="goPage(item.path,item.checked)">
						<view class="item-image">
							<image :src="item.icon" style="width:100upx;height:100upx"></image>
						</view>
						<view class="item-text">{{item.title}}</view>
					</view>
				</view> -->
			</view>
			<!-- F2 在线办事 |办事指南 结束 -->

			<!-- F3 社区便民中心 开始 -->
			<view class="second-container">
				<view class="second-box">
					<image src="@/static/image/index/banner.png" mode="widthFix"></image>
				</view>
			</view>
			<!-- F3 社区便民中心 结束 -->

			<!-- F4 抗击疫情标题栏 开始 -->
			<view class="title-box">
				<image src="@/static/image/index/epidemic-icon.png" mode="widthFix"></image>
				<view>抗击新冠疫情</view>
				<view>截至 {{closeDate}}</view>
			</view>
			<!-- F4 抗击疫情标题栏 结束 -->

			<!-- F5 抗击疫情数据展示 开始 -->
			<view class="epidemic-container">
				<view class="epidemic-box" v-for="(item,index) in epidemicSituation" :key="index">
					<view class="epidemic-Count">
						<image :src="item.bg" mode="widthFix"></image>
						<view class="content-box">
							<view class="content">
								<view>疑似病例</view>
								<view class="text"><text class="num-1">{{item.borderlineCase}}</text>人</view>
							</view>
							<view class="content">
								<view>新增病例</view>
								<view class="text"><text class="num-2">{{item.newCase}}</text>人</view>
							</view>
							<view class="content">
								<view>确诊病例</view>
								<view class="text"><text class="num-3">{{item.comfirmCase}}</text>人</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- F5 抗击疫情数据展示 结束 -->

			<!-- F6 乡村公告 标题栏 开始 -->
			<view class="title-box">
				<image src="@/static/image/index/news-icon.png" mode="widthFix"></image>
				<view style="border: 0;">乡村公告</view>
			</view>
			<!-- F6 乡村公告 标题栏 结束 -->

			<!-- F7 乡村公告 列表 开始 -->
			<view class="third-container" v-if="newsList.length != 0">
				<view v-for="(news,index) in newsList" :key="index" style="padding:10upx 20upx;" @click="navContent(news)">
					<view class="newsItem" :style="{borderBottom: index == newsList.length-1 ? '0':'1px solid #edeef0'}">
						<view style="height:220upx">
							<view style="height:190upx;width:240upx">
								<image :src="news.coverImageUrl || noPhoto" style="width: 100%;height:100%;border-radius: 10upx;"></image>
							</view>
						</view>
						<view style="width: calc(100% - 210upx);padding-left:30upx">
							<view class="activity_title">
								{{news.title}}
							</view>
							<view class="activity_count">
								<view style="float:left">{{news.publishTime}}</view>
							</view>
						</view>
					</view>

				</view>
			</view>
			<!-- F7 乡村公告 列表 结束 -->
			<view style="height: 140upx;"></view>
		</view>
		<wx-tabbar></wx-tabbar>

	</view>
</template>

<script>
	import easySelect from '@/components/easy-select/easy-select.vue'
	import uniEasyInput from '@/components/uni-easyinput/uni-easyinput.vue'
	import uniNoticeBar from '@/components/uni-notice-bar/uni-notice-bar.vue'
	import wxTabbar from '@/components/wx-tabbar/wx-tabbar.vue'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				weather: {
					weather: "",
					temp: ""
				},
				player: "",
				topImage: 'https://cdjjyl.com.cn/imageCollection/jiange/indexImage/bg_top.png',
				areaCode: this.$api.util.getAreaCode(),
				areaName: "",
				communityTitle: "剑阁智慧广电乡村服务平台",
				communityList: [],
				inputTitle: "",
				placeholderStyle: "color:white;font-size:20upx",
				noticeText: "通知：乡村已开通便民服务，请前往乡村进行登记！",
				noPhoto: "https://cdjjyl.com.cn/imageCollection/jiange/noPhoto.png",
				newsList: [],
				// 菜单
				fristBoxList: [{
						icon: require('@/static/image/index/report.png'),
						title: '事件上报',
						path: '/pages/report/reportlist',
						checked: 'LOGIN'
					},
					{
						icon: require('@/static/image/index/advice.png'),
						title: '投诉建议',
						path: '/pages/suggestions/suggestions',
						checked: 'LOGIN'
					},
					{
						icon: require('@/static/image/index/partService.png'),
						title: '党建服务',
						path: '/pages/party/partyBuild',
						checked: 'LOGIN'
					},
					{
						icon: require('@/static/image/index/rules.png'),
						title: '三务公开',
						path: '/pages/threeAffairs/threeAffairs',
						checked: 'LOGIN'
					},
					{
						icon: require('@/static/image/index/armyHonor.png'),
						title: '军兵光荣',
						path: '/pages/armyHonor/armyHonor',
						checked: 'LOGIN'
					},
					{
						icon: require('@/static/image/index/epidemic-situation.png'),
						title: '疫情防控',
						path: '/pages/epidemic/controlEpidemic',
						checked: 'LOGIN'
					},
					{
						icon: require('@/static/image/index/express.png'),
						title: '乡邻达',
						path: '/pages/express/expressManager',
						checked: 'LOGIN'
					},
					{
						icon: require('@/static/image/index/more.png'),
						title: '就业创业',
						path: '/pages/getJob/getJob',
						checked: 'LOGIN'
					},

				],
				// 疫情展示框
				epidemicSituation: [{
						bg: require('@/static/image/index/epidemic-count.png'),
						borderlineCase: '0',
						newCase: '1354',
						comfirmCase: '165423',
					},
					{
						bg: require('@/static/image/index/epidemic-localCount.png'),
						borderlineCase: '1',
						newCase: '1354',
						comfirmCase: '165423',
					},
				],
				closeDate: "2022.5.12 14:27"
			}
		},

		onLoad() {
			this.getWeather();
			this.getNoticeByAreaCode();
			this.inquiryArticle()
			this.inquiryEpidemic()
		},
		onShow(option) {
			uni.hideTabBar()
			// 从分包界面返回到首页需要重新设置tabbar的index值
			this.changeTabBar({
				index: 0
			})
		},

		methods: {
			...mapMutations(['changeTabBar']),
			getWeather() {
				this.$api.request.getWeather({}, (res) => {
					if (res.body.status.statusCode == '0') {
						this.weather = res.body.data.lives[0]
					}
				})
			},
			getNoticeByAreaCode() {
				let params = {
					areaCode: this.areaCode
				}
				this.$api.request.getNoticeByAreaCode(params, (res) => {
					if (res.body.status.statusCode == '0') {
						if (res.body.data.entity) {
							this.noticeText = res.body.data.entity.title
						}
					}
				})
			},
			// 查询疫情防控信息
			inquiryEpidemic() {
				this.$api.request.inquiryEpidemic({}, (res) => {
					if (res.body.status.statusCode == '0') {
						let cityEpidemic = res.body.data.cityEpidemic;
						let provinceEpidemic = res.body.data.provinceEpidemic;
						this.closeDate = cityEpidemic.lastUpdateTime
						this.epidemicSituation[0].borderlineCase = provinceEpidemic.total.suspect
						this.epidemicSituation[0].newCase = provinceEpidemic.total.newConfirm
						this.epidemicSituation[0].comfirmCase = provinceEpidemic.total.confirm
						this.epidemicSituation[1].borderlineCase = cityEpidemic.total.suspect
						this.epidemicSituation[1].newCase = cityEpidemic.total.newConfirm
						this.epidemicSituation[1].comfirmCase = cityEpidemic.total.confirm
					}
				})
			},
			navContent(item) {
				let decodeItem = encodeURIComponent(JSON.stringify(item));
				if (item.linkType === '自定义内容') {
					uni.navigateTo({
						url: '/pages/content/richText?item=' + decodeItem
					})
				} else if (item.linkType === '外部链接') {
					uni.navigateTo({
						url: '/pages/content/webView?src=' + item.content
					})
				}
			},
			// 不校验登录跳转
			goPage(url, checked) {
				console.log('===============', url);
				if (url == "" || url == undefined || url == null) {
					this.$api.msg("该功能暂未开放")
				}
				if ("NONE" == checked) {
					if (url == "/pages/index/functions") {
						this.changeTabBar({
							index: 1
						})
						uni.switchTab({
							url: url
						})
					} else {
						uni.navigateTo({
							url: '/pages/decalare/declareIndex'
						})
					}

				} else if ("LOGIN" == checked) {
					this.$api.sysauth.checkLogin(url);
				} else if ("OWNER" == checked) {
					this.$api.sysauth.checkLoginAndBindCommunity(url);
				} else if ("URL" == checked) {
					window.location.href = url
				}

			},
			navTo() {
				// uni.navigateTo({
				// 	url: "/pages/index/video-test"
				// })
				// window.open('https://m.lzxrmtzx.com/index.html')
			},
			inquiryArticle() {
				this.$api.request.inquiryArticlePagination({
					areaCode: this.areaCode,
					articleType: "NOTICE",
					startIndex: 1,
					pageSize: 3,
					published: true
				}, (res) => {
					if (res.body.status.statusCode === '0') {
						this.newsList = res.body.data.articles;
					}
				}, true)
			},
		},
		computed: {
			...mapState(['defaultCommunityId']),
		},
		components: {
			easySelect,
			uniEasyInput,
			uniNoticeBar,
			wxTabbar
		}
	}
</script>

<style lang="scss">
	page {
		background: $page-color-base;
	}

	// 乡村公告列表
	.newsItem {
		display: flex;
		flex-direction: row;
		border-bottom: 1px solid #edeef0;

	}

	//在线办理 办事指南
	.problem-box {
		display: flex;
		justify-content: space-between;

		image {
			width: 330rpx;
			height: 128rpx;
		}
	}

	//标题栏
	.title-box {
		display: flex;
		align-items: center;
		margin: 24rpx 0;

		image {
			margin-right: 10rpx;
			width: 32rpx;
			height: 32rpx;
		}

		:nth-child(2) {
			padding-right: 10rpx;
			border-right: 4rpx solid #D9DEE5;
			margin-right: 10rpx;
			font-size: 24rpx;
			font-weight: 700;
		}

		:nth-child(3) {
			color: #ABAEB2;
		}
	}

	// 抗击疫情总容器
	.epidemic-container {
		display: flex;
		justify-content: space-between;
	}

	// 抗击疫情块容器
	.epidemic-box {
		position: relative;

		.epidemic-Count {
			image {
				width: 330rpx;
				height: 240rpx;
			}
		}

		.content-box {
			margin: 52rpx 12rpx 0 12rpx;
			width: 306rpx;
			height: 176rpx;
			position: absolute;
			top: 0;

			.content {
				display: flex;
				padding: 10rpx;
				justify-content: space-between;

				view:nth-child(1) {
					font-size: 24rpx;
					font-weight: 400;
				}

				.text {
					color: #ABAEB2;

					text {
						font-size: 32rpx;
						margin-right: 10rpx;
					}

					.num-1 {
						color: #25C722;

					}

					.num-2 {
						color: #3E9CF9;
					}

					.num-3 {
						color: #FF5C5C;
					}
				}
			}
		}
	}

	.container {
		width: 100%;
		height: 100%;
	}


	.top-box {
		width: 100%;
		height: 500upx;
		position: relative;
		overflow: hidden;

		.bg {
			position: absolute;
			top: 0;
			left: 0;
			z-index: 0;
			width: 100%;
		}

		.top-content {
			position: absolute;
			top: 0;
			left: 0;
			z-index: 100;
			width: 100%;
		}

		.top-title {
			margin-top: 50upx;
			z-index: 100;
			padding-left: 30upx;
			font-size: 32upx;
			color: white;
		}

		.top-notice {
			background-color: white;
			margin: 20upx 30upx 0upx 30upx;
			border-radius: 20upx;
		}

		.top-search {
			width: 100%;
			margin-top: 30upx;
			display: flex;
			flex-direction: row;

			.top-location {
				height: 60upx;
				width: 40%;
				line-height: 60upx;
				padding: 0 30upx;
				display: flex;
				flex-direction: row;
				align-items: center;
			}

			.search-input-box {
				width: calc(60% - 80upx);
				margin-left: 40upx;

				.search-input {
					background-color: #E9E9E9;
					width: 100%;
					height: 100%;
					box-sizing: border-box;
					line-height: 50upx;
					border-radius: 50upx;
					font-size: 24upx;
					transition: all .5s;
					padding: 10upx 30upx 10upx 90upx;
				}

				.search-input-p {
					color: #999;
					width: 100%;
					height: 100%;
					padding: 0 !important;
				}

				.search-input-p-c {
					position: relative;
					top: 50%;
					transform: translateY(-50%);
				}

			}
		}
	}

	.info-box {
		width: calc(100% - 60upx);
		margin: 20upx 30upx 0upx 30upx;
		position: absolute;
		top: 280upx;
		z-index: 80;

		.first-container {
			width: 100%;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			border-radius: 20upx;
			padding-bottom: 10upx;

			.item {
				padding: 18rpx;
				text-align: center;

				image {
					width: 114rpx;
					height: 114rpx;
				}
			}

			.first-box {
				padding: 20upx 30upx;
				display: flex;
				flex-direction: row;
				justify-content: space-around;

				.item-box {
					width: 25%;
					text-align: center;

					.item-image {
						width: 100%;

						image {
							width: 120upx;
							height: 120upx;
						}
					}

					.item-text {
						width: 100%;
						text-align: center;
						font-size: 24upx;
						font-weight: bold;
					}
				}
			}

			.second-box {
				padding: 0 20upx 20upx 20upx;
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;
				border-radius: 20upx;

				.item-box {
					margin: 10rpx 0 20rpx 0;
					width: 25%;
					text-align: center;

					.item-image {
						width: 100%;

						image {
							width: 100upx;
							height: 100upx;
						}
					}

					.item-text {
						width: 100%;
						text-align: center;
						font-size: 22upx;
					}
				}
			}
		}


		.second-container {
			margin-top: 30upx;
			width: 100%;
			// background-color: white;
			border-radius: 20upx;
			padding-bottom: 10upx;

			.title-box {
				text-align: center;
				padding-top: 20upx;
				height: 80upx;
				line-height: 80upx;
				font-weight: bolder;
				font-size: 30upx;
			}

			.second-box {
				// padding: 0 20upx 20upx 20upx;
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;
				border-radius: 20upx;

				image {
					width: 690rpx;
					height: 200rpx;
					border-radius: 16rpx;
				}

				.item-box {
					margin: 10rpx 0 20rpx 0;
					width: 25%;
					text-align: center;

					.item-image {
						width: 100%;

						image {
							width: 100upx;
							height: 100upx;
						}
					}

					.item-text {
						width: 100%;
						text-align: center;
						font-size: 22upx;
					}
				}
			}
		}


		.third-container {
			margin-top: 30upx;
			width: 100%;
			background-color: white;
			border-radius: 20upx;
			padding-bottom: 10upx;
			padding-top: 20upx;

			.title-box {
				text-align: center;
				padding-top: 20upx;
				height: 80upx;
				line-height: 80upx;
				font-weight: bolder;
				font-size: 30upx;
			}
		}
	}

	.activity_title {
		font-weight: bold;
		margin-top: 10upx;
		font-size: 24upx;
		line-height: 40upx;
		margin-bottom: 20upx;
		height: 120upx;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 3;
		overflow: hidden;
	}

	.activity_count {
		height: 40upx;
		color: #929292;
		line-height: 40upx;
		font-size: 20upx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}

	.easy-select {
		border: none !important;
		color: white !important;
		width: 240upx !important;

		.active {
			background-color: #69BEFF !important;
		}
	}

	.easy-select-options {
		background-color: #FFFFFF !important;
		border: #1786FF !important;
		box-shadow: 0px 0px 20px #909090 !important;
	}

	.easy-select-options-item {
		color: rgba(0, 0, 0, 0.5) !important;
		font-size: 24upx !important;
		height: 60upx !important;
		line-height: 60upx !important;
	}

	.uni-easyinput__content {
		background-color: #39B9F8 !important;
		width: 100% !important;
		border-radius: 60upx !important;
		height: 60upx !important;
		min-height: 60upx !important;
	}

	.content-clear-icon {
		padding: 0 20upx !important;
	}

	.uni-easyinput__content-input {
		font-size: 22upx !important;
		color: white !important;
	}

	.uni-icons {
		color: white !important;
		font-size: 30upx !important;
	}

	.uni-noticebar {
		padding: 20upx 30upx !important;
		background-color: transparent !important;
	}

	/deep/ .uni-noticebar-icon {
		color: #65B1F3 !important
	}

	.uni-noticebar__content-text {
		font-size: 24upx !important;
	}
</style>
